package de.negativrekord.blockworld;

import cc.creativecomputing.CCApp;
import cc.creativecomputing.control.CCControl;
import cc.creativecomputing.graphics.CCGraphics;
import cc.creativecomputing.math.CCVector3f;

import com.riekoff.particlecubeworld.editor.visual.AVisual;

import de.negativrekord.blockworld.MultiPathGenerator.StartPositions;
import de.negativrekord.blockworld.geometry.BlockCreatorPresets;


public class BlockWorldVisual implements AVisual{

	int MAP_W = 100;
	int MAP_H = 100;
	int N_VERTICES = MAP_W*MAP_H*2*24*3;
	int W = 20;
	int scale0 = 10;
	int scale1 = 4;
	
	
	
	@CCControl(name="cam", min=0, max=1)
	int _cCam = 0;
	
	
	private BlockCreatorPresets _myBlockCreator; 
	private KnnClassifier _myClassifier;
	private MultiPathGenerator _myPathGenerator;
	
	@CCControl(name="renderer")
	private TileworldRenderer _myRenderer;
	
	int[][] map0 = new int[MAP_W/10][MAP_H/10];
	int[][] map1 = new int[MAP_W][MAP_H];	
	
	CCVector3f pos = new CCVector3f(0,0,0);
	CCVector3f lastPos = new CCVector3f(0,0,0);
	CCVector3f dir = new CCVector3f(0,0,0);
	
	int flash = 0;
	CCGraphics g;
	
	
	public BlockWorldVisual (CCApp theApp) {
		g = theApp.g;
	
	
		_myBlockCreator = new BlockCreatorPresets(N_VERTICES);
		_myBlockCreator.preset(3);
		
		_myClassifier = new KnnClassifier();
		_myClassifier.init(g);
		
		_myPathGenerator = new MultiPathGenerator (20, StartPositions.RANDOM, 3000, 0, 200, 0);
//		_myPathGenerator.addPath(PathStyle.CIRCLE, 2000, 0);
		
		//addControls("app", "app", this);
	}
	
	float timePassed = 0;
	
	
	public void update (float theDeltaTime) {

		_myPathGenerator.update(theDeltaTime);		
		_myClassifier.clearPrototypes();
		for (int i=0; i<4; i++) {
			_myClassifier.addPrototype(new CCVector3f(_myPathGenerator.pos(i).x,0,_myPathGenerator.pos(i).y), i);
		}
		_myClassifier.init(g);
	}

	public void draw (CCGraphics g) {
		g.pushMatrix();
		g.scale(2);
		_myBlockCreator.mesh().draw(g);
		g.popMatrix();
	}
}
